/* 
 * File:   player.h
 * Author: TELKOM-CIS
 *
 * Created on 05 Maret 2011, 14:06
 */

#ifndef PLAYER_H

#define	PLAYER_H

#ifndef OBJECT_H
#include "Object.h"
#endif

#ifndef FIELD_H
#include "field.h"
#endif

#ifndef FRUIT_H
#include "Fruit.h"
    #include "BuahCabai.h"
    #include "BuahJagung.h"
    #include "BuahJamur.h"
    #include "BuahMangga.h"
    #include "BuahMelon.h"
    #include "BuahPisang.h"
    #include "BuahWortel.h"
#endif

#ifndef BIBIT_H
#include "bibit.h"
#endif

#ifndef CABAI_H
#include "cabai.h"
#endif

#ifndef MANGGA_H
#include "mangga.h"
#endif

#ifndef JAGUNG_H
#include "jagung.h"
#endif

#ifndef JAMUR_H
#include "jamur.h"
#endif

#ifndef MELON_H
#include "melon.h"
#endif

#ifndef PISANG_H
#include "pisang.h"
#endif

#ifndef WORTEL_H
#include "wortel.h"
#endif

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <cstring>
#include <vector>

using namespace std;

typedef struct{
    int x;
    int y;
}point;

typedef struct{
    point up;
    point down;
    point left;
    point right;
    point mid;
} pos;

enum direction {left,right,up,down};

//void gotoxy(int x, int y);

class player: public Object{
private:
    /********************************/
    /*          PROPERTIES          */
    /********************************/
    pos location;
    /* player.location.mid  :   <x,y>
     * player.location.left : <x-1,y>
     * player.location.right: <x+1,y>
     * player.location.up   :   <x,y-1>
     * player.location.down :   <x,y+1> */
    point vektor;   //player.vector = <x,y>
    int face;       //where the player face (0.left, 1.right, 2.up, 3.down)
    int area;       //area: 0-home, 1-farm, 2-shop
    string name;    //name of the player. used fo save game.
    int AP;         //sigma action point per day
    int money;      //the sum of money the player has
	const int MAX_AP;	//defaul max value for AP
    
public:
    vector <Object*> inventory1; //inventory 1
    vector <Object*> inventory2; //inventory 2
    vector <Object*> inventory3; //inventory 3 --- Perlu di destroy ga?
    /********************************/
    /*          Inheritance         */
    /********************************/
    int getObjectType() const;
    /********************************/
    /*      CTOR, CCTOR, DTOR       */
    /********************************/
    player();
    player (const player&);
    ~player();
    
    /*********************************/
    /*            METHODS            */
    /*********************************/
    //=========  change vector ============
    void turn_left();
    void turn_right();
    void turn_up();
    void turn_down();

    //=============  getter  ==============
    int getAP();
    point getpos();
	point getvektor() const;
    string getName();
    int getMoney();
	int getArea();
	int getFace();
	int getMAXAP() const;
	bool isInvEmpty(int) const;
	//getInvAt perilakunya tidak terdefinisi jika inventory tersebut kosong !!! cek dulu isInvEmpty baru pake method ini
	Object* getInvAt(int) const;
	int getInvSize(int) const;

    //=============  setter  ==============
    void setAP(int);
    void setpos(int, int);  //set player position
    void setvektor(point);
	void setFace (int);     //set the direction player face
	void setName(string);
    void setMoney(int);
	void setArea(int);
	void setInventory(int,int,int); //masukin ke inventory (OTOMATIS ERASE, BARU INSERT ITEM)
    
    //==========  other methods  ==========
    void displaypos();      //display player position in x,y coordinate
    void screenPos();       //display player position in UI console
    void moveLeft();        //move player left
    void moveRight();       //move player right
    void moveUp();          //move player up
    void moveDown();        //move player down
    void move();            //move player with reading keyboard input
    void walk(int, int);    //Set walk step as much as <int>

    /******************************************************/
    /*      CORELATION WITH CLASS PLANT, BUAH, BIBIT      */
    /******************************************************/
    void slash(field *);
    //slash a true isMature/isHarvest/isDied plant
    //remove a plant from ground. Reset the field. 1 AP used
    //read class Plant and it's inheritance
    void plow(field *);
    //plow a square of field to plant a seed.
    //set isPlow true. 1 AP used
    //read class Plant and it's inheritance
    void water(field *);
    //water a square of field whether it contain Plant or no
    //set isWatered true. Level up 1 Happy Meter. 1 AP used
    //read class Plant and it's inheritance
    void harvest(field *);
    //harvest a square of field containing plant which isHarvest = true
    //change status to isDied = true, or revert to isMature = true. 1 AP used
    //read class Buah, class Plant and it's inheritance
    void eat(int);
    //eat an inventory item which isFood true. Nothing happened when isFood false
    //read class Buah, class Plant and it's inheritance
    void put(int, int, field*);
    //discard or sow the seed. put or discard the plant
    //read class Buah, class Plant and it's inheritance
    void buy(int, int);
    //buy item from store
    //read class Bibit
    void sell(int, int);
    //sell item from inventory
    //read class Bibit, class Buah
    void displayInventory();
    //show all item in player inventory and the quantity
    //access player property inventory

    /****************************************/
    /*      CORELATION WITH CLASS MAP       */
    /****************************************/
    void sleep();
    //go to sleep, replenish players.AP, change the day, set all field to isWatered false
    //can only be used if player.area = home
    //access class Field, class Plant
};

#endif	/* PLAYER_H */

